home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MCASM.RAR / MC_ASM.EXE / WROX_ASM / CH13 / C13_1.ASM next >
Assembly Source File  |  1994-11-23  |  1KB  |  62 lines

  1. ;
  2. ; Program 13.1 Handling Conventional Memory via DOS
  3. ;
  4. .286
  5. dosseg
  6. .model small
  7. .stack 100h
  8. .data
  9.     ptr1    dw ?
  10. .code
  11. ; When a program starts DS and ES both point to PSP.
  12. ; I use unmodified ES as segment address of the beginning of
  13. ; the program space.
  14.  
  15. Start:
  16.         mov ax,@data
  17.         mov ds,ax        ; Load data segment
  18.  
  19.         mov bx,ss
  20.         sub bx,ax
  21.         shl bx,4
  22.         cli
  23.         mov ss,ax        ; Load stack pointer
  24.         add sp,bx
  25.         sti
  26.  
  27.         mov bx,sp
  28.         add bx,15        ; Round up to next paragraph
  29.         shr bx,4
  30.         add ax,bx        ; AX = SS + SP / 16 = segment address
  31.                     ; of the end of the program space
  32.         mov bx,es
  33.         sub ax,bx        ; AX = required ammount of paragraphs
  34.         mov bx,ax
  35.         mov ah,4ah
  36.         int 21h         ; Resize block
  37.         jc Resize_Error
  38.  
  39.         mov ah,48h        ; Allocate
  40.         mov bx,1000        ; 16K
  41.         int 21h
  42.         jc Alloc_Error
  43.         mov ptr1,ax
  44. ;        . . .
  45.         mov ah,4Ah        ; Resize up to
  46.         mov bx,2000        ; 32K
  47.         mov es,ptr1
  48.         int 21h
  49.         jc Resize_Error
  50. ;        . . .
  51.         mov ah,49h        ; Free block
  52.         mov es,ptr1
  53.         int 21h
  54.         jc Free_Error
  55.         xor al,al        ; Successful
  56. Resize_Error:
  57. Alloc_Error:
  58. Free_Error:
  59.         mov ah,4ch
  60.         int 21h
  61. end Start
  62.